/**
 * 系统初始化配置面板
 */
Ext.namespace("Ext.ux.sysconfig");

Ext.ux.sysconfig.SysConfigPanel = Ext.extend(Ext.Panel, {

	layout: 'fit',
	border: false,
	
	ctx: null,	//当前应用名称
	grid: null,

	initComponent:function(){
		Ext.ux.sysconfig.SysConfigPanel.superclass.initComponent.call(this);
		
		var gridStructure = [{  
			name: 'id',
			hidden: true
		},{
			name: 'key',  
			header: '配置项'
		},{  
			name: 'memo',  
			header: '配置项说明'
		},{  
			name: 'value',  
			header: '配置值'
		}];
	   
		var grid = new Ext.ux.grid.BasicGrid({
			structure: gridStructure,
			url: 'sys-config!list.action',
			defaultSortField: 'key',  
			idField: 'id',
			title: '系统初始化配置管理',
			region: 'center',
			margins: "1 1 1 1",
			actioncolumn: {
				xtype: 'actioncolumn',
				width: 8,
				items: [{
					icon: this.ctx + '/resources/images/icons/16_16/cog_edit.png',
					handler: function(grid, rowIndex, colIndex) {
						grid.getSelectionModel().selectRow(rowIndex);
						var item = grid.getSelectionModel().getSelected();
						this.editItem(item);
					},
					scope: this,
					tooltip: '修改配置值'
				}]
			}
		});
		this.add(grid);
		this.grid = grid;
	},
	
	editItem: function(item){
		var key = item.get('key');
		var memo = item.get('memo');

		var editItemWin = new Ext.ux.sysconfig.EditItemWindow({
			itemKey: key,
			itemMemo: memo,
			parentPanelId: this.id,
			ctx: this.ctx
		});
		editItemWin.show();
	},
	
	refresh: function(){
		this.grid.store.reload();
	}
});